package main

import (
	"fmt"
	"reflect"
	"unsafe"
)

//别名申明
type numAlis int32

func main() {

	var i uint8 = 1
	fmt.Print("uint8所占用的字节数：")
	fmt.Print(unsafe.Sizeof(i))
	fmt.Println()
	var j uint32 = 1
	fmt.Print("uint32所占用的字节数：")
	fmt.Print(unsafe.Sizeof(j))
	fmt.Println()
	var a uint16 = 1
	fmt.Print("uint16所占用的字节数：")
	fmt.Print(unsafe.Sizeof(a))
	fmt.Println()
	var b uint = 1
	fmt.Print("uint(无符号)所占用的字节数：【无符号时，会根据当前系统操作位数获取，64位则8个字节，32位则4个字节】")
	fmt.Print(unsafe.Sizeof(b))
	fmt.Println()
	var c float32 = 1
	fmt.Print("float32所占字节数：")
	fmt.Print(unsafe.Sizeof(c))
	fmt.Println()
	var d bool = false
	fmt.Print("bool所占字节数：")
	fmt.Print(unsafe.Sizeof(d))
	fmt.Println()
	fmt.Print("bool内容：")
	fmt.Print(d)
	fmt.Println()
	var f byte = 1
	fmt.Print("byte所占字节数：")
	fmt.Print(unsafe.Sizeof(f))
	fmt.Println()
	var g rune = 1
	fmt.Print("rune所占字节数：")
	fmt.Print(unsafe.Sizeof(g))
	fmt.Println()
	//设置类型别名
	alis()

}

/*
	类型零值 类型别名
*/
func alis() {
	var i int32
	var j float32
	var b bool
	var d complex64
	var e string
	//设置的类型别名
	var f numAlis

	fmt.Print("int32:")
	fmt.Print(i)
	fmt.Println()
	fmt.Print("float32:")
	fmt.Print(j)
	fmt.Println()
	fmt.Print("bool:")
	fmt.Print(b)
	fmt.Println()
	fmt.Print("complex64:")
	fmt.Print(d)
	fmt.Println()
	fmt.Print("string:")
	fmt.Print(e)
	fmt.Println()
	fmt.Print("numAlis默认值:")
	fmt.Print(f)
	fmt.Println()
	fmt.Print("numAlis的数据类型为:")
	fmt.Print(reflect.TypeOf(f))
	fmt.Println()
	fmt.Print("numAlis别名占用的空间大小为:")
	fmt.Print(unsafe.Sizeof(f))
	fmt.Println()
	fmt.Println("numAlis的数据类型只能与numAlis的数据类型相加，不能与int32类型相加")

}
